package com.hzya.frame.system.role.controller;

import com.hzya.frame.system.role.entity.RoleModuleEntity;
import com.hzya.frame.system.role.service.IRoleModuleService;
import com.hzya.frame.utils.core.action.DefaultController;
import com.hzya.frame.utils.core.entity.JsonResultEntity;
import com.hzya.frame.utils.core.page.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @description: 角色模块  controller
 * @tableName: system_role_module 
 * @entityName: RoleModuleEntity
 * 包含：
 * 1、分页查询(queryPaged)
 * 2、index页面(goIndexPage)
 * 3、新增页面(goAddPage)
 * 4、新增信息保存(save)
 * 5、修改页面(goEditPage)
 * 6、修改信息保存(update)
 * 7、信息查看(goShowPage)
 * 8、删除信息(delete)
 * @author: gjh
 * @history: 1.0
 */

@Controller("system_role_module")
@RequestMapping("/system/role/module/RoleModuleController")
public class RoleModuleController extends DefaultController {
    @Autowired
    protected IRoleModuleService  rolemoduleService;

    /** 角色模块分页信息 **/
    @RequestMapping(value = "queryPaged")
    @ResponseBody
    public PageInfo<RoleModuleEntity> queryPaged(RoleModuleEntity entity) throws Exception {
		PageInfo<RoleModuleEntity> page =null;
		try {
		   page = rolemoduleService.queryPaged(entity);
		} catch (Exception e) {
		    e.printStackTrace();
		}
		return page;
    }

	/** 跳转到角色模块的index页面 **/
    @RequestMapping(value = "goIndexPage", method = RequestMethod.GET)
    public ModelAndView goIndexPage() {
		ModelAndView view = new ModelAndView();
		/**这里根据实际的需要填写需要传到前台的对象**/
		//view.addObject(attributeName, attributeValue);
		/**这里是返回对应的页面路径**/
		view.setViewName("/system/role/module/rolemodule/list");
		return view;
    }

	/** 跳转到角色模块信息新增页面 **/
    @RequestMapping(value = "goAddPage")
    public ModelAndView goAddPage() {
		ModelAndView view = new ModelAndView();
		/**这里根据实际的需要填写需要传到前台的对象**/
		//view.addObject(attributeName, attributeValue);
		/**这里是返回对应的页面路径**/
		view.setViewName("/system/role/module/rolemodule/add");
		return view;
    }
    
    /** 角色模块新增信息保存 **/
    @RequestMapping(value = "save", method = RequestMethod.POST)
    @ResponseBody
    public JsonResultEntity save(RoleModuleEntity entity) {
		try {
		    rolemoduleService.save(entity);
		    return getSuccessMessageEntity("保存成功", "save");
		} catch (Exception e) {
		    logger.error("save", e);
		    e.printStackTrace();
		    return getFailureMessageEntity("保存失败！"+e.getMessage(), "save");
		}
    }
    
    /** 跳转到角色模块信息修改页面 **/
    @RequestMapping(value = "edit/{id}")
    public ModelAndView goEditPage(@PathVariable("id") Long id) {
		ModelAndView view = new ModelAndView();
		/**这里根据实际的需要填写需要传到前台的对象**/
		RoleModuleEntity entity = rolemoduleService.get(id);
		view.addObject("entity", entity);
		/**这里是返回对应的页面路径**/
		view.setViewName("/system/role/module/rolemodule/edit");
		return view;
    }
    
    /** 角色模块修改信息保存 **/
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public JsonResultEntity update(RoleModuleEntity entity) {
		try {
		    rolemoduleService.update(entity);
		    return getSuccessMessageEntity("更新成功！", "update");
		} catch (Exception e) {
		    logger.error("update", e);
		    e.printStackTrace();
		    return getFailureMessageEntity("更新失败！"+e.getMessage(), "update");
		}
    }
    
    /** 跳转到角色模块信息查看 **/
    @RequestMapping(value = "show/{id}")
    public ModelAndView goShowPage(@PathVariable("id") Long id) {
		ModelAndView view = new ModelAndView();
		/**这里根据实际的需要填写需要传到前台的对象**/
		RoleModuleEntity entity = rolemoduleService.get(id);
		view.addObject("entity", entity);
		/**这里是返回对应的页面路径**/
		view.setViewName("/system/role/module/rolemodule/show");
		return view;
    }

	/** 删除角色模块信息 **/
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    @ResponseBody
    public JsonResultEntity delete(Long id) {
		try {
		    rolemoduleService.logicRemove(id);
		    return getSuccessMessageEntity("删除成功！", "delete");
		} catch (Exception e) {
		    logger.error("delete", e);
		    e.printStackTrace();
		    return getFailureMessageEntity("删除失败！"+e.getMessage(), "delete");
		}
    }
}

